<?php
 if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class User extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        //$this->checkAdmin($this->session->userdata('admin_id'));
        $this->data['controller'] = 'user';         
        $this->load->model('Muser');
    }
    
    public function loginMobile()
    {
        $mobile = $this->getParamString('mobile');
        $upass = $this->getParamString('password');
        die(json_encode($this->Muser->loginMobileDb($mobile,$upass)));
    }
    
     public function loginFacebook()
    {
        $fbid = $this->getParamString('fbid'); 
        die(json_encode($this->Muser->loginFacebookDB($fbid)));   
    }
    public function loginGoogle()
    {
        $ggid = $this->getParamString('ggid');
        die(json_encode($this->Muser->loginGoogleDb($ggid)));
    }
    
    public function saveinfo()
    {
        die(json_encode($this->Muser->saveinfoDB()));
    }

    public function changepass()
    {
        die(json_encode($this->Muser->changePassDB()));
    }
    
    public function forgotpass()
    {
        $mobile = $this->getParamString('mobile');
        die(json_encode($this->Muser->forGotDB()));
    }
    
    public function registerMobile()
    {
        die(json_encode($this->Muser->registerMobileDb($this->data['baseurl'])));   
    }
    
    public function registerFacebook()
    {
//        echo "fdasfasdf";die;
        $fbid  = $this->getParamString('fbid');
        $email = $this->getParamString('email');
        $fullname = $this->getParamString('fullname');
        $avatar = $this->getParamString('avatar');  
        die(json_encode($this->Muser->registerFaceBookDb($fbid,$email,$fullname,$avatar)));   
    }
    
    public function registerFacebookOther()
    {
//        echo "fdasfasdf";die;
        $fbid  = $this->getParamString('fbid');
        $email = $this->getParamString('email');
        $fullname = $this->getParamString('fullname');
//        $avatar = $this->getParamString('avatar');  
        die(json_encode($this->Muser->registerFaceBookOtherDb($fbid,$email,$fullname)));   
    }
    
    public function resendCodeMobile()
    {
        die(json_encode($this->Muser->resendCodeMobileDb($this->data['baseurl'])));   
    }
    
    public function registerGoogleOther()
    {
        $ggid  = $this->getParamString('ggid');
        $email = $this->getParamString('email');
        $fullname = $this->getParamString('fullname');
//        $avatar = $this->getParamString('avatar');  
        die(json_encode($this->Muser->registerGoogleOtherDb($ggid,$email,$fullname)));   
    }
    
    public function registerGoogle()
    {
        $ggid  = $this->getParamString('ggid');
        $email = $this->getParamString('email');
        $fullname = $this->getParamString('fullname');
        $avatar = $this->getParamString('avatar');  
        die(json_encode($this->Muser->registerGoogleDb($ggid,$email,$fullname,$avatar)));   
    }
    
    public function verifyaccount()
    {
        die(json_encode($this->Muser->verifyaccountDB()));   
    }
    
   public function getagegroup(){
        die(json_encode($this->Muser->getAgeGroup())); 
   }
    
    public function getjob(){
        die(json_encode($this->Muser->getJob()));
    }
		
	public function activeuser(){
		echo $this->Muser->activeUser();
	}	
       
	public function getInfoUser()
	{
		$mobile = $this->getParamInt('mobile');
                $upass = $this->getParamString('password');
                $fbid = $this->getParamString('fbid');
                $ggid = $this->getParamString('ggid');
//                var_dump($mobile,$upass,$fbid,$ggid);die;
                if (!in_array($mobile, array(null, '', '0')))
                {
                    die(json_encode($this->Muser->loginMobileDb($mobile,$upass)));
                }
                if (!in_array($fbid, array(null, '', '0')))
                {
                    die(json_encode($this->Muser->loginFacebookDb($fbid)));
                }
                if (!in_array($ggid, array(null, '', '0')))
                {
                    die(json_encode($this->Muser->loginGoogleDb($ggid)));
                }
                return (object) array('status' => 201, 'description' => 'Tham số không đúng');
                
                
	}
	
	public function upAvatar()
	{
//            echo "dfasfsdaf";die;
		$img=$this->getParamString('img');
//                $img=$_REQUEST['img'];
		$id=$this->getParamInt('id');
//                var_dump($img,$id);die;
		die(json_encode($this->Muser->upAvatarDb($img,$id)));
	}
        public function editAvatar()
	{
//            echo "dfasfsdaf";die;
		$img=$this->getParamString('img');
//                $img=$_REQUEST['img'];
		$id=$this->getParamInt('id');
//                var_dump($img,$id);die;
		die(json_encode($this->Muser->editAvatarDb($img,$id)));
	}
        public function editAvatarOther()
	{
//            echo "dfasfsdaf";die;
//		$img=$this->getParamString('img');
//                $img=$_REQUEST['img'];
		$id=$this->getParamInt('id');
//                var_dump($img,$id);die;
		die(json_encode($this->Muser->editAvatarOtherDb($id)));
	}
        public function deleteAvatar()
	{
//            echo "dfasfsdaf";die;
//		$img=$this->getParamString('img');
//                $img=$_REQUEST['img'];
		$id=$this->getParamInt('id');
//                var_dump($img,$id);die;
		die(json_encode($this->Muser->deleteAvatarDb($id)));
	}
	
        public function upAvatarOther()
	{
//            echo "dfasfsdaf";die;
//		$img=$this->getParamString('img');
//                $img=$_REQUEST['img'];
		$id=$this->getParamInt('id');
//                var_dump($img,$id);die;
		die(json_encode($this->Muser->upAvatarOtherDb($id)));
	}
	public function activeMobile()
	{
		$mobile=$this->getParamString('mobile');
		$code=$this->getParamString('code');
		die(json_encode($this->Muser->activeMobileDb($mobile,$code)));
	}
	
	public function saveinfothefirst()
    {
        die(json_encode($this->Muser->saveinfothefirstDB()));
    }
        
        //Get all user status =0
        public function getUserSms()
	{
		$stt=$this->getParamInt('stt');
		die(json_encode($this->Muser->getUserSmsDb($stt)));
	}
        
        public function updateUserSms()
	{
		$phone=$this->getParamString('phone');
		$code_active=$this->getParamString('code_active');
		die(json_encode($this->Muser->updateUserSmsDb($phone,$code_active)));
	}
        
         public function resetSmsPassword()
	{
		$type=$this->getParamString('type');
		$code=$this->getParamString('code');
		$mobile=$this->getParamString('mobile');
		$money=$this->getParamString('money');
		$signature=$this->getParamString('signature');
                $data = "type=" . $type . "&code=" . $code . "&mobile=" . $mobile . "&money=" . $money;
                $signatureHash = hash_hmac("sha256", $data, 'nhatnv-dev-20150716083800:skype-nhat.89');
                if($signatureHash == $signature)
                {
                    die(json_encode($this->Muser->resetSmsPasswordDb($mobile)));
                }
	}
}
